using System.IO.Abstractions.TestingHelpers;
using Shouldly;
using Stryker.Abstractions.Exceptions;
using Stryker.Abstractions.Options.Inputs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Stryker.Core.UnitTest;

namespace Stryker.Core.UnitTest.Options.Inputs;

[TestClass]
public class OutputPathInputTests : TestBase
{
    private MockFileSystem _fileSystemMock = new MockFileSystem();

    [TestMethod]
    public void ShouldHaveHelpText()
    {
        var target = new OutputPathInput();
        target.HelpText.ShouldBe("Changes the output path for Stryker logs and reports. This can be an absolute or relative path.");
    }

    [TestMethod]
    [DataRow("C:/bla/test")]
    [DataRow("test")]
    public void ShouldReturnValidOutputPath(string outputPath)
    {
        var target = new OutputPathInput { SuppliedInput = outputPath };
        _fileSystemMock.AddDirectory(outputPath);

        var result = target.Validate(_fileSystemMock);

        // we can't assert the complete datetime as it will differ in milliseconds
        result.ShouldBe(result);
    }

    [TestMethod]
    [DataRow("C:/bla/test")]
    [DataRow("test")]
    public void ShouldThrowOnNonExistingPath(string outputPath)
    {
        var target = new OutputPathInput { SuppliedInput = outputPath };

        var exception = Should.Throw<InputException>(() =>
        {
            target.Validate(_fileSystemMock);
        });
        // we can't assert the complete datetime as it will differ in milliseconds
        exception.Message.ShouldBe("Outputpath should exist");
    }

    [TestMethod]
    [DataRow(null)]
    [DataRow("")]
    [DataRow("   ")]
    public void ShouldThrowOnEmptyValue(string value)
    {
        var target = new OutputPathInput { SuppliedInput = value };

        var exception = Should.Throw<InputException>(() =>
        {
            target.Validate(_fileSystemMock);
        });

        exception.Message.ShouldBe("Outputpath can't be null or whitespace");
    }
}
